| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | Static Public Member Functions | List of all members
nkScripts::Environment Class Referencefinal

Defines an environment in which scripts can execute. More...

## Public Member Functions
NK_FORCE_EXPORT_CALL | ~Environment ()
const ExecutionResult & | getLastExecutionResult () const
nkMemory::StringView | getName () const
void | setEnvironmentFor (INTERPRETER interpretType)
void | setName (nkMemory::StringView name)
bool | execute (const Script &script)
void | requestGarbageCollection ()
void | setVar (nkMemory::StringView name, bool value)
void | setVar (nkMemory::StringView name, int value)
void | setVar (nkMemory::StringView name, float value)
void | setVar (nkMemory::StringView name, double value)
void | setVar (nkMemory::StringView name, const char *value)
void | setVar (nkMemory::StringView name, nkMemory::StringView value)
void | setVar (nkMemory::StringView name, const ScriptObjectReference &value)
void | setObject (nkMemory::StringView name, nkMemory::StringView userTypeName, void *value)
bool | isVarSet (nkMemory::StringView name)
bool | getVar (nkMemory::StringView name, bool defaultValue)
int | getVar (nkMemory::StringView name, int defaultValue)
float | getVar (nkMemory::StringView name, float defaultValue)
double | getVar (nkMemory::StringView name, double defaultValue)
nkMemory::StringView | getVar (nkMemory::StringView name, const char *defaultValue)
nkMemory::StringView | getVar (nkMemory::StringView name, nkMemory::StringView defaultValue)
ScriptObjectReference | getVar (nkMemory::StringView name)
void * | getObject (nkMemory::StringView name, nkMemory::StringView userTypeName=nullptr)
ScriptObjectReference | getScriptFunction (nkMemory::StringView name)
Function * | setFunc (nkMemory::StringView name)
bool | isFuncSet (nkMemory::StringView name)
Function * | getFunc (nkMemory::StringView name)
UserType * | setUserType (nkMemory::StringView name)
bool | isUserTypeSet (nkMemory::StringView name)
UserType * | getUserType (nkMemory::StringView name)
Namespace * | setNamespace (nkMemory::StringView name)
bool | isNamespaceSet (nkMemory::StringView name)
Namespace * | getNamespace (nkMemory::StringView name)
bool | callScriptFunction (const ScriptObjectReference &reference, const DataStack &args, DataStack &expectedOutput)
nkMemory::Buffer | serializeScriptObject (const ScriptObjectReference &reference, bool forwardUserDataOwnership=false)
ScriptObjectReference | deserializeScriptObject (nkMemory::BufferView< unsigned char > object)

## Static Public Member Functions
static nkMemory::UniquePtr< Environment > | create () noexcept
static nkMemory::UniquePtr< Environment > | create (Environment &&other) noexcept

## Detailed Description

Defines an environment in which scripts can execute.

It can be seen as a context in which structures and objects can be defined and accessed.

## Constructor & Destructor Documentation

## ◆ ~Environment()

NK_FORCE_EXPORT_CALL nkScripts::Environment::~Environment | ( |  | ) |

Destructor.

## Member Function Documentation

## ◆ getLastExecutionResult()

const ExecutionResult& nkScripts::Environment::getLastExecutionResult | ( |  | ) | const

Returns
  The last execution result.

## ◆ getName()

nkMemory::StringView nkScripts::Environment::getName | ( |  | ) | const

Returns
  The name attached to the environment.

## ◆ setEnvironmentFor()

void nkScripts::Environment::setEnvironmentFor | ( | INTERPRETER | interpretType | ) |

Sets the interpreter the environment should be ready for.

Parameters

  interpretType | The type of interpreter to use.

## ◆ setName()

void nkScripts::Environment::setName | ( | nkMemory::StringView | name | ) |

Sets the name of the environment.

Parameters

  name | The name to set.

Remarks
  In theory, this should not be called from external code, but only from the EnvironmentManager.

## ◆ execute()

bool nkScripts::Environment::execute | ( | const Script & | script | ) |

Requests the execution of a script within the environment.

Parameters

  script | The script to execute.

Returns
  Whether the execution went fine (true) or not (false). If an error occurred, result can be checked through getLastExecutionResult().

## ◆ requestGarbageCollection()

void nkScripts::Environment::requestGarbageCollection | ( |  | ) |

Requests a garbage collection within the environment.

## ◆ setVar() [1/7]

void nkScripts::Environment::setVar | ( | nkMemory::StringView | name,
|  | bool | value
| ) |  |

Sets a variable within the environment.

Parameters

  name | The name of the variable to set.
  value | The value to assign to it.

## ◆ setVar() [2/7]

void nkScripts::Environment::setVar | ( | nkMemory::StringView | name,
|  | int | value
| ) |  |

Sets a variable within the environment.

Parameters

  name | The name of the variable to set.
  value | The value to assign to it.

## ◆ setVar() [3/7]

void nkScripts::Environment::setVar | ( | nkMemory::StringView | name,
|  | float | value
| ) |  |

Sets a variable within the environment.

Parameters

  name | The name of the variable to set.
  value | The value to assign to it.

## ◆ setVar() [4/7]

void nkScripts::Environment::setVar | ( | nkMemory::StringView | name,
|  | double | value
| ) |  |

Sets a variable within the environment.

Parameters

  name | The name of the variable to set.
  value | The value to assign to it.

## ◆ setVar() [5/7]

void nkScripts::Environment::setVar | ( | nkMemory::StringView | name,
|  | const char * | value
| ) |  |

Sets a variable within the environment.

Parameters

  name | The name of the variable to set.
  value | The value to assign to it.

## ◆ setVar() [6/7]

void nkScripts::Environment::setVar | ( | nkMemory::StringView | name,
|  | nkMemory::StringView | value
| ) |  |

Sets a variable within the environment.

Parameters

  name | The name of the variable to set.
  value | The value to assign to it.

## ◆ setVar() [7/7]

void nkScripts::Environment::setVar | ( | nkMemory::StringView | name,
|  | const ScriptObjectReference & | value
| ) |  |

Sets a variable within the environment.

Parameters

  name | The name of the variable to set.
  value | The value to assign to it.

## ◆ setObject()

void nkScripts::Environment::setObject | ( | nkMemory::StringView | name,
|  | nkMemory::StringView | userTypeName,
|  | void * | value
| ) |  |

Sets an object within the environment.

Parameters

  name | The name of the object to set.
  userTypeName | The type name of the user data to set.
  value | The user data to assign to it.

## ◆ isVarSet()

bool nkScripts::Environment::isVarSet | ( | nkMemory::StringView | name | ) |

Checks whether a variable is existing in the environment.

Parameters

  name | The name of the variable to check.

## ◆ getVar() [1/7]

bool nkScripts::Environment::getVar | ( | nkMemory::StringView | name,
|  | bool | defaultValue
| ) |  |

Retrieves a variable, if it exists.

Parameters

  name | The name of the variable to retrieve the value from.
  defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type.

Returns
  The variable value in the environment if it exists and is of requested type.

Remarks
  It is possible to access a variable through a path, for instance "v.type.valid".

## ◆ getVar() [2/7]

int nkScripts::Environment::getVar | ( | nkMemory::StringView | name,
|  | int | defaultValue
| ) |  |

Retrieves a variable, if it exists.

Parameters

  name | The name of the variable to retrieve the value from.
  defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type.

Returns
  The variable value in the environment if it exists and is of requested type.

Remarks
  It is possible to access a variable through a path, for instance "v.type.x".

## ◆ getVar() [3/7]

float nkScripts::Environment::getVar | ( | nkMemory::StringView | name,
|  | float | defaultValue
| ) |  |

Retrieves a variable, if it exists.

Parameters

  name | The name of the variable to retrieve the value from.
  defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type.

Returns
  The variable value in the environment if it exists and is of requested type.

Remarks
  It is possible to access a variable through a path, for instance "v.type.offset".

## ◆ getVar() [4/7]

double nkScripts::Environment::getVar | ( | nkMemory::StringView | name,
|  | double | defaultValue
| ) |  |

Retrieves a variable, if it exists.

Parameters

  name | The name of the variable to retrieve the value from.
  defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type.

Returns
  The variable value in the environment if it exists and is of requested type.

Remarks
  It is possible to access a variable through a path, for instance "v.type.offset".

## ◆ getVar() [5/7]

nkMemory::StringView nkScripts::Environment::getVar | ( | nkMemory::StringView | name,
|  | const char * | defaultValue
| ) |  |

Retrieves a variable, if it exists.

Parameters

  name | The name of the variable to retrieve the value from.
  defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type.

Returns
  The variable value in the environment if it exists and is of requested type.

Remarks
  It is possible to access a variable through a path, for instance "v.type.name".

## ◆ getVar() [6/7]

nkMemory::StringView nkScripts::Environment::getVar | ( | nkMemory::StringView | name,
|  | nkMemory::StringView | defaultValue
| ) |  |

Retrieves a variable, if it exists.

Parameters

  name | The name of the variable to retrieve the value from.
  defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type.

Returns
  The variable value in the environment if it exists and is of requested type.

Remarks
  It is possible to access a variable through a path, for instance "v.type.name".

## ◆ getVar() [7/7]

ScriptObjectReference nkScripts::Environment::getVar | ( | nkMemory::StringView | name | ) |

Retrieves a variable, if it exists.

Parameters

  name | The name of the variable to retrieve the value from.

Returns
  A reference over the variable in the environment.

Remarks
  It is possible to access a variable through a path, for instance "v.type.object".

## ◆ getObject()

void* nkScripts::Environment::getObject | ( | nkMemory::StringView | name,
|  | nkMemory::StringView | userTypeName = `nullptr`
| ) |  |

Retrieves an object if it exists.

Parameters

  name | The name of the variable to retrieve the object from.
  userTypeName | If needed, the type name can be specified to ensure pointer returned is of the right type.

Returns
  A pointer over the user data linked, if it exists and is of the type specified.

Remarks
  It is possible to leave the type name empty, preventing the retrieval from checking the user data type before returning it. It is also possible to access a variable through a path, for instance "v.type.describer".

## ◆ getScriptFunction()

ScriptObjectReference nkScripts::Environment::getScriptFunction | ( | nkMemory::StringView | name | ) |

Retrieves a reference over a function defined in the scripting environment.

Parameters

  name | The name of the function to retrieve.

Returns
  A reference over the requested function, if it exists.

Remarks
  It is possible to access a function through a path, for instance "v.type.getName".

## ◆ setFunc()

Function* nkScripts::Environment::setFunc | ( | nkMemory::StringView | name | ) |

Sets a function within the environment.

Parameters

  name | The name of the function to set.

Returns
  The function information holder to populate.

Remarks
  The environment owns the Function memory. External code should not delete it.

## ◆ isFuncSet()

bool nkScripts::Environment::isFuncSet | ( | nkMemory::StringView | name | ) |

Checks whether a function is existing within the environment.

Parameters

  name | The name of the function to check.

Returns
  Whether the function exists (true) or no (false).

## ◆ getFunc()

Function* nkScripts::Environment::getFunc | ( | nkMemory::StringView | name | ) |

Parameters

  name | The name of the function to retrieve.

Returns
  The function requested if it exists, nullptr else.

## ◆ setUserType()

UserType* nkScripts::Environment::setUserType | ( | nkMemory::StringView | name | ) |

Sets a user type within the environment.

Parameters

  name | The name of the user type to set. It is possible to shortcut into namespaces using a syntax like ns0.ns1.UserTypeName.

Returns
  The user type information holder to populate.

Remarks
  The environment owns the UserType memory. External code should not delete it.

## ◆ isUserTypeSet()

bool nkScripts::Environment::isUserTypeSet | ( | nkMemory::StringView | name | ) |

Checks whether a user type is existing within the environment.

Parameters

  name | The name of the user type to check. It is possible to shortcut into namespaces using a syntax like ns0.ns1.UserTypeName.

Returns
  Whether the user type exists (true) or not (false).

## ◆ getUserType()

UserType* nkScripts::Environment::getUserType | ( | nkMemory::StringView | name | ) |

Parameters

  name | The name of the user type to retrieve. It is possible to shortcut into namespaces using a syntax like ns0.ns1.UserTypeName.

Returns
  The user type requested if it exists, nullptr else.

## ◆ setNamespace()

Namespace* nkScripts::Environment::setNamespace | ( | nkMemory::StringView | name | ) |

Sets a namespace within the environment.

Parameters

  name | The name of the namespace to set. It is possible to shortcut into namespaces using a syntax like ns0.ns1.ns2.

Remarks
  The environment owns the Namespace memory. External code should not delete it.

## ◆ isNamespaceSet()

bool nkScripts::Environment::isNamespaceSet | ( | nkMemory::StringView | name | ) |

Checks whether a namespace is existing within the environment.

Parameters

  name | The name of the namespace to check. It is possible to shortcut into namespaces using a syntax like ns0.ns1.ns2.

Returns
  Whether the namespace exists (true) or not (false).

## ◆ getNamespace()

Namespace* nkScripts::Environment::getNamespace | ( | nkMemory::StringView | name | ) |

Parameters

  name | The name of the namespace to retrieve. It is possible to shortcut into namespaces using a syntax like ns0.ns1.ns2.

Returns
  The namespace requested if it exists, nullptr else.

## ◆ callScriptFunction()

bool nkScripts::Environment::callScriptFunction | ( | const ScriptObjectReference & | reference,
|  | const DataStack & | args,
|  | DataStack & | expectedOutput
| ) |  |

Calls a script function from the C++ environment.

Parameters

  reference | The function reference, in the environment.
  args | The arguments to provide to the function, in a stack.
  expectedOutput | A ready stack that will receive the output of the called function.

Returns
  If the function could successfully be called (true) or not (false).

## ◆ serializeScriptObject()

nkMemory::Buffer nkScripts::Environment::serializeScriptObject | ( | const ScriptObjectReference & | reference,
|  | bool | forwardUserDataOwnership = `false`
| ) |  |

Serializes an object from the environment into a binary buffer. This can be used to pass a script object from one environment to another, for instance.

Parameters

  reference | The reference in the environment of the object to serialize.
  forwardUserDataOwnership | Whether the user data, defined by user types, should also forward their ownership to the serialization object (true) or not (false). \ This will ultimately transmit the ownsership to the environment where it is deserialized.

Returns
  The binary buffer containing the serialized data.

## ◆ deserializeScriptObject()

ScriptObjectReference nkScripts::Environment::deserializeScriptObject | ( | nkMemory::BufferView< unsigned char > | object | ) |

Deserializes a binary buffer into a new object within the environment.

Parameters

  object | The serialized binary buffer to deserialize.

Returns
  A reference over the object created within the environment, using the serialized information.

## ◆ create() [1/2]

static nkMemory::UniquePtr<Environment> nkScripts::Environment::create | ( |  | ) |
| static noexcept

Creates a standalone resource. This method can be used to allocate a resource and manually manage its lifetime.

Returns
  The created resource instance.

## ◆ create() [2/2]

static nkMemory::UniquePtr<Environment> nkScripts::Environment::create | ( | Environment && | other | ) |
| static noexcept

Creates a standalone resource by moving another. This method can be used to allocate a resource and manually manage its lifetime.

Returns
  The created resource instance.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsScripts/Environments/Environment.h